package com.ll.homework;

/**
 * @author 刘龙
 * @version 1.0
 * 人
 */
public class Person {
    private String name;
    private Vehicles vehicles;

    public Person(String name, Vehicles vehicles) {
        this.name = name;
        this.vehicles = vehicles;
    }

    /**
     * 过河 使用的交通工具是船
     */
    public void passRiver() {
        // vehicles = null => vehicles instanceof Boat => false
        // vehicles = 马对象 => vehicles instanceof Boat => false
        // vehicles = 船对象 => vehicles instanceof Boat => true
        if (!(vehicles instanceof Boat)) {
            vehicles = VehicleFactory.getBoat();
        }
       vehicles.work();
    }

    /**
     * 一般情况下 使用的交通工具是马
     */
    public void common() {
        if (!(vehicles instanceof Horse)) {
            vehicles = VehicleFactory.getHorse();
        }
        vehicles.work();
    }

    public void fireMountain(){
        if (!(vehicles instanceof Airplane)) {
            vehicles = VehicleFactory.getAirplane();
        }
        vehicles.work();
    }
}
